package com.meisiabc.app.service;

import com.meisiabc.support.email.EmailClient;
import lombok.extern.slf4j.Slf4j;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import static com.meisiabc.app.support.StringPool.EMAIL_TEMPLATE;

@Slf4j
@Service
public class EmailService {
    @Value("${meisi.mail.from.username}")
    private String from;

    @Autowired
    private EmailClient emailClient;

    @Async
    public void sendEmail(String teacherEmail, String teacherName, String studentName, String zoomId, DateTime scheduledate, String getClassTimeEnd, DateTime now) {
        log.info("sendEmail");
        String content = String.format(EMAIL_TEMPLATE, teacherName, studentName, zoomId, scheduledate.toString("yyyy-MM-dd HH:mm"), getClassTimeEnd, now.toString("yyyy-MM-dd"));
        emailClient.send(from, teacherEmail, "Student Leave Request", content);
    }
}
